<template>
	<view class="home-page">
		<u-navbar leftIconColor="rgba(255,255,255,0.0)" :autoBack="false" :placeholder="true"
			bgColor="rgba(255,255,255,0.0)">
			<view slot="center" class="nav-title">
				資訊
			</view>
		</u-navbar>
		<view class="content">
			<scroll-view scroll-x="true">
				<view class="tab-box" :style="'width:'+150*tabList.length+'rpx'">
					<view :class="current == index?'active-item': 'tab-item'" class="tab-item"
						v-for="(item,index) in tabList" :key="index" @click="cutTab(index,item.id)">
						{{item.name}}
					</view>
				</view>
			</scroll-view>
			<view class="news">
				<view class="news-item" v-for="(item,index) in List" :key="index" @click="goDetails(item.categoryId,item.title)">
					<image :src="item.picUrl" mode=""></image>
					<view class="news-content">
						<view class="news-title">
							{{item.title}}
						</view>
						<view class="news-text">
							{{item.introduction}}
						</view>
						<view class="news-text">
							{{$u.timeFormat(item.createTime, 'yyyy.mm.dd')}}
						</view>
					</view>
				</view>
				<u-loadmore loading-text="努力加載中" loadmore-text="輕輕上拉" nomore-text="沒有更多了" :status="status"
					margin-top="20" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [],
				current: 0,
				categoryId: 0,
				page: 1,
				List: [],
				status: 'loadmore',
			}
		},
		onLoad() {
			this.getlist()
		},
		onReachBottom() {
			this.page = ++this.page
			this.postgorylist()
		},
		methods: {
			getlist() {
				this.$Request({
					method: 'GET',
					url: '/app-api/promotion/article-category/list',
					data: {},
					ismsg: false,
				}).then(res => {
					console.log(res)
					if (res.code == 0) {
						this.tabList = res.data
						this.categoryId = this.tabList[0].id
						this.postgorylist()
					}
				})
			},
			postgorylist() {
				let params = {
					categoryId: this.categoryId,
					pageNo: this.page,
					pageSize: 10

				}
				this.$Request({
					method: 'GET',
					url: '/app-api/promotion/article/page',
					data: params,
					ismsg: false,
				}).then(res => {
					console.log(res)
					if (res.code == 0) {
						if (res.data.list.length < 10) {
							this.status = 'nomore';
						}
						if (this.page == 1) {
							this.List = res.data.list
						} else {
							this.List = [...this.List, ...res.data.list]
						}
					}
				})
			},
			cutTab(index, id) {
				this.current = index
				this.categoryId = id
				this.page = 1
				this.postgorylist()
			},
			goDetails(id,title) {
				uni.navigateTo({
					url: '/pages/real-time/details/index?id=' + id +'&title='+title
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #FBFBFB;
	}
</style>
<style lang="scss" scoped>
	.home-page {
		background-image: url('../../static/real/home-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 362rpx;
		min-height: 80vh;

		.nav-title {
			color: #fff;
		}

		.content {
			padding: 30rpx;

			.tab-box {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.tab-item {
					padding: 10rpx 20rpx;
					border-radius: 10rpx;
					background-color: rgba(255, 255, 255, 0.16);
					color: #fff;
					font-size: 26rpx;
				}

				.active-item {
					background-color: #fff;
					color: #18BE8C;
				}
			}

			.news {
				.news-item {
					background-color: #fff;
					border-radius: 30rpx;
					margin-top: 30rpx;
					box-shadow: 0rpx 3rpx 32rpx 1rpx rgba(0, 0, 0, 0.08);

					image {
						width: 100%;
						height: 360rpx;
					}

					.news-content {
						padding: 0 20rpx 20rpx;

						.news-title {
							font-weight: bold;
							color: #333333;
							font-size: 28rpx;
							margin-top: 20rpx;
						}

						.news-text {
							margin-top: 15rpx;
							color: #999999;
							font-size: 24rpx;
						}
					}
				}
			}
		}
	}
</style>